﻿using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TrackIT.Common.ViewModel;

namespace TrackIT.UnitTest
{
    [TestClass]
    public class ViewModelBaseTest
    {
        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        [DeploymentItem("TrackIT.Common.dll")]
        public void OnPropertyChangedTest()
        {
            TestViewModel tvm = new TestViewModel();

            string expectedPropertyName = string.Empty;

            tvm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                Assert.AreEqual(sender, tvm);
                Assert.AreEqual(e.PropertyName, expectedPropertyName);
            };

            expectedPropertyName = "Property1";
            tvm.FireOnPropertyChanged(expectedPropertyName);

            expectedPropertyName = "Property2";
            tvm.FireOnPropertyChanged(expectedPropertyName);
        }

        // Just make the test class concrete for testing, and allow access to OnPropertyChanged
        class TestViewModel : ViewModelBase
        {
            public void FireOnPropertyChanged(string propertyName)
            {
                OnPropertyChanged(propertyName);
            }
        }
    }
}
